package org.example.zuoye.config;

import org.example.zuoye.common.JwtInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author xinchen
 * @Date: 2024/08/14/ 10:25
 * @Description 配置类
 */
// @Configuration
public class MyWebConfig implements WebMvcConfigurer {
    /**
     * 因为这个类是自己创建交给spring管理的，所以可以依赖注入的方式获取值
     */
    @Value("${jwt.secret.key}")
    private String jwtSecretKey;

    @Override
    public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) {
        registry.addInterceptor(new JwtInterceptor(jwtSecretKey))
                .addPathPatterns("/api/v1/**")
                .excludePathPatterns("/api/v1/admin/login/**")
                .excludePathPatterns("/api/v1/admin/logout/**")
                .excludePathPatterns("/api/v1/admin/captcha/**")
                .excludePathPatterns("/api/v1/uploads/avatar/**");
    }
}
